
<div class="row animate fadeIn">
    <form id="" class="form-horizontal"  method="post">
       <?php foreach ($reading_data as $rd) { ?>
      <div class="ibox-title" style="border:none;"><h5 style="color: #00afef"><i>View Meter Reading</i></h5>
        <input type="hidden" value="<?php echo $rd->account_id; ?>" name="hidden_acct_read_id">
        <input type="hidden" value="<?php echo $rd->consumed; ?>"   name="hidden_consumed">
        <input type="hidden" value="<?php echo $rd->reading_id; ?>" name="hidden_reading">
      </div>





        <div class="ibox-content" id="">
            <div>
              <div class="form-inline form-group" >
                <div><label class="col-lg-3 control-label">Period From :</label>
                    <div class="col-lg-4">
                        <label id="" class="control-label"><?php echo $rd->prev_date; ?></label>
                    </div>
                </div>
                <div><label class="col-lg-2 control-label">Period To :</label>
                    <div class="col-lg-2">
                          <label name="" class="control-label"><?php echo $rd->reading_date; ?></label>
                    </div>
                </div>
              </div>
              <div class="form-inline form-group" >
                  <div><label class="col-lg-3 control-label">Billing Date :</label>
                      <div class="col-lg-4">
                          <label name="" class="control-label"><?php echo $rd->reading_date; ?></label>
                      </div>
                  </div>
                  <div><label class="col-lg-2 control-label">Due Date :</label>
                      <div class="col-lg-2">
                            <label name="" class="control-label"><?php echo $rd->due_date; ?></label>
                      </div>
                  </div>
              </div>
              <div class="form-inline form-group" >
                  <div><label class="col-lg-3 control-label">Account No :</label>
                      <div class="col-lg-4">
                          <label id="" class="control-label"><?php echo $rd->acct_num; ?></label>
                      </div>
                  </div>
              </div>
              <div class="form-inline form-group" >
                  <div><label class="col-lg-3 control-label">Account Name :</label>
                      <div class="col-lg-4">
                          <label id="" class="control-label"><?php echo $rd->acct_name; ?></label>
                      </div>
                  </div>
                  <div><label class="col-lg-2 control-label">Address :</label>
                      <div class="col-lg-2">
                            <label id="" class="control-label"><?php echo $rd->street_address; ?></label>
                      </div>
                  </div>
              </div>
              <div class="form-inline form-group" >
                  <div><label class="col-lg-3 control-label">Previous :</label>
                      <div class="col-lg-4">
                          <label id="" class="control-label"><?php echo $rd->prev_read; ?></label>
                      </div>
                  </div>
                  <div><label class="col-lg-2 control-label">Present :</label>
                      <div class="col-lg-2">
                          <label id="" class="control-label"><?php echo $rd->meter_reading; ?></label>
                      </div>
                  </div>
              </div>
              <div class="form-inline form-group" >
                  <div><label class="col-lg-3 control-label">Consumed :</label>
                      <div class="col-lg-4">
                          <label id="" class="control-label"><?php echo $rd->consumed; ?></label>
                      </div>
                  </div>
              </div>
              <div class="form-inline form-group" >
                <div class="col-lg-1"></div>
                <table id=""class="col-lg-3 table" style="width: 75%;margin-bottom:0px;">
                  <thead>
                    <tr>
                      <th style="padding:8px;text-align:center;width:20px;">Consumption</th>
                      <th style="padding:8px;text-align:center;">Description</th>
                      <th style="padding:8px;text-align:center;width:110px;">Equal Amount</th>
                    </tr>
                  </thead>
                  <tbody id="consump_sched_view">
                    
                  </tbody>
                </table> 
              </div>


              <div class="form-inline form-group" >
                  <div><label class="col-lg-8 control-label" style="padding-right:0px;">Sub Total :</label>
                      <div class="col-lg-4">
                          <label id="" class="control-label" style="margin-left:10px;"><?php echo $rd->read_amt; ?></label>
                      </div>
                  </div>
              </div>
              <div class="form-inline form-group" >
                  <div><label class="col-lg-8 control-label" style="padding-right:0px;">Previous Balance :</label>
                      <div class="col-lg-4">
                          <label id="" class="control-label" style="margin-left:10px;"><?php echo $rd->bill_bal; ?></label>
                      </div>
                  </div>
              </div>
              <!--  -->
              <div id="charges_list_view">

              </div>

              <div class="form-inline form-group" >
                  <div><label class="col-lg-8 control-label" style="padding-right:0px;">TOTAL :</label>
                      <div class="col-lg-4">
                          <label id="" class="control-label" style="margin-left:10px;"><?php echo $rd->curchg; ?></label>
                      </div>
                  </div>
              </div>
              
              <!-- <div class="form-inline form-group" >
                <div><label class="col-lg-4 control-label"></label>
                  <div class="col-lg-2">
                    <a id = "" class="btn btn-sm btn-outline btn-info">Calculate</a>
                  </div>
              </div>   -->
              
            </div>  
        </div>  
        <?php } ?>  
    </form>
</div>
            
      <script>
$(document).ready(function(){
  $(".chosen-select").chosen({width:"100%;"});
  
  $('input[name=date_read]').val(new Date().toJSON().slice(0,10));

  var name,prev_rdate,prev_read;
  var address;
  var due_date,cur_date,bm,byr;
  var accountID,accountNum,list_id;
  var cur_total,sub_total = 0;
  var current_read,consumed,bill_bal,total_due,max_rate = 0;
  var consumed = $('input[name=hidden_consumed]').val();

   $.ajax({
            type  : "POST",
            url   : "<?php echo base_url($this->session->userdata('forajax') . '/getcharges_rates_v'); ?>",
            dataType : 'json',
            data  : { "acct_id" : $('input[name=hidden_acct_read_id]').val() , "reading_id" : $('input[name=hidden_reading]').val() },
            success : function(e){
    // ------------- RATES --------------
              $('#consump_sched_view').empty();         
              var trHTML = '';
              var temp1 = consumed;
              var temp2 = consumed;
              console.log(consumed);
              $.each(e.r1, function(i, item) {
                if((temp2 - e.r1[i].usage_qty) <= 0 ){
                  if(e.r1[i].min_flag == 'Y'){
                    var temp_amt = e.r1[i].usage_qty * e.r1[i].rate;
                    trHTML += '<tr><td text-align:right;>' + e.r1[i].usage_qty + '</td><td text-align:right;>' + e.r1[i].description + '</td><td text-align:right;>' + parseFloat(temp_amt).toFixed(2) + '</td></tr>';
                    
                    return false;
                  }else{
                     var temp_amt = temp1 * e.r1[i].rate;
                     var qty_dis = temp1;
                     if(temp1 < 10){
                      qty_dis = ('0' + temp1).slice(-2);
                     }
                     trHTML += '<tr><td text-align:right;>' + qty_dis + '</td><td text-align:right;>' + e.r1[i].description + '</td><td text-align:right;>' + parseFloat(temp_amt).toFixed(2)  + '</td></tr>';
                     
                     return false;
                  }
                }else{
                  var temp_deduc = (temp1 - (temp2-e.r1[i].usage_qty));
                  var temp_amt = temp_deduc* e.r1[i].rate;
                  
                  temp1 = (temp1 - temp_deduc)
                  trHTML += '<tr><td text-align:right;>' +temp_deduc + '</td><td text-align:right;>' + e.r1[i].description + '</td><td text-align:right;>' + parseFloat(temp_amt).toFixed(2) + '</td></tr>';
                  
                }
                 //trHTML += '<tr><td text-align:right;>' + e.r1[i].usage_qty + '</td><td text-align:right;>' + e.r1[i].description + '</td><td text-align:right;>' + e.r1[i].rate + '</td></tr>';
              });
             
              $('#consump_sched_view').append(trHTML);
    
    // ------------- CHARGES--------------
      $('#charges_list_view').html('');
            var trHTML2 = '';
          $.each(e.r2, function(i, item) {
                trHTML2 += '<div class="form-inline form-group" ><div><label class="col-lg-8 control-label" style="padding-right:0px;">'+ e.r2[i].charge_description+' :</label><div class="col-lg-4"><label id="sub_total_v" class="control-label" style="margin-left:10px;">'+ parseFloat(e.r2[i].charge_amount).toFixed(2) +'</label></div></div></div>';
              });
            $('#charges_list_view').append(trHTML2);

            } ,
                complete: function(data) {
                      $('#cur_calculate').removeAttr('disabled');

                },
                beforeSend: function(){
                      $('#cur_calculate').attr('disabled',true);
                }
          });
  





























 /-----------------       ------------------/
  $('#viewX').click(function(){
           close_view();
        });
 });
       
</script>
